package com.nbjtjc.safe.mapper.danger;

import com.nbjtjc.safe.model.danger.DangerInspectListPublic;
import com.nbjtjc.util.MyMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

@Mapper
public interface DangerInspectListPublicMapper extends MyMapper<DangerInspectListPublic> {

    List<DangerInspectListPublic> search(@Param("dilp") DangerInspectListPublic dangerInspectListPublic);

    List<DangerInspectListPublic> searchNoAssociateUserName(@Param("dilp") DangerInspectListPublic dangerInspectListPublic);

    @Select("select * from danger_inspect_list_public where inspect_public_id=#{ipId}")
    List<DangerInspectListPublic> findByInspectPublicId(@Param("ipId") int inspectPublicId);

    @Delete("delete  from danger_inspect_list_public where inspect_public_id=#{ipId}")
    int deleteByInspectPublicId(@Param("ipId") int inspectPublicId);


    /**
     * 获取隐患排查检查单下的隐患是否有整改超期
     * @param now
     * @param inspectPublicId
     * @return
     */
    @Select("select count(*) from danger_inspect_list_public where need_change=1 and change_time is null " +
            "  and deadline < #{now} and inspect_public_id=#{ipId}")
    int findReformOverTime(@Param("now") Date now,@Param("ipId") int inspectPublicId);

    /**
     * 获取隐患排查检查单下的隐患是否有督办超期
     * @param now
     * @param inspectPublicId
     * @return
     */
    @Select("select count(*) from danger_inspect_list_public where need_change=1 " +
            " and supervise_finish_date is not null  and supervise_reform_time is null" +
            "  and supervise_finish_date < #{now} and inspect_public_id=#{ipId}")
    int findSuperviseOverTime(@Param("now") Date now,@Param("ipId") int inspectPublicId);

    @Select("<script>"+
            "select * from danger_inspect_list_public " +
            "where inspect_public_id in" +
            " <foreach item='inspectPublicId' index='index' collection='inspectPublicIds'  open='(' separator=',' close=')'> " +
            "#{inspectPublicId}" +
            " </foreach> "
            + "</script>")
    List<DangerInspectListPublic> findByDangerInspectPublicId(@Param("inspectPublicIds") List<Integer> inspectPublicIds);

}